#include "LogManager.h"

ReturnStatus LogManager::addLog(const string&log_type,int user_id,int device_id,const string&log_content){
    if(Database.connect()==ReturnStatus::SUCCESS){
        
        string query = "INSERT INTO logs (log_type, user_id,device_id,log_content,timestamp) VALUES ('"+log_type+"','"+to_string(static_cast<int>(user_id))+"','"+to_string(static_cast<int>(device_id))+"', '"+log_content+"','"+GET_CURRENT_TIME()+"')";
        if(Database.executeQuery(query)==ReturnStatus::SUCCESS){
            cout<<DEVICEADDSUCCESS<<endl;
            return SUCCESS;
        }
    }
    cout<<DEVICEADDFAILURE<<endl;
    return FAILURE;
}
vector<Log> LogManager::getLogs(int userId,Role role){
    vector<Log> results;
    if(Database.connect()==ReturnStatus::SUCCESS){
            string query = "SELECT * FROM logs";
            vector<string> results = Database.fetchResults(query,TABLELOG);
    }else{
        string query = "SELECT * FROM logs WHERE user_id = "+to_string(userId);
        vector<string> results = Database.fetchResults(query,TABLEDEVICE);
    }
    return results;
}
